import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:get/get.dart';

import '../../utils/colors.dart';
import '../../utils/http_util.dart';

class InfoPage extends StatefulWidget {
  final String title;
  final String api;
  const InfoPage(this.title,this.api,{super.key});

  @override
  State<InfoPage> createState() => _InfoPageState();
}

class _InfoPageState extends State<InfoPage> {
  String info = '';

  @override
  void initState() {
    super.initState();
    _queryDetail();
  }

  Future<void> _queryDetail() async {
    EasyLoading.show(status: 'loading', maskType: EasyLoadingMaskType.clear);
    try {
      final result = await HttpUtil().get(
        widget.api,
      );
      final dynamic responseData = result.data['data']; // 明确类型声明
      setState(() {
        info = responseData['content'];
      });
    } catch (e) {
      EasyLoading.showToast('请求失败');
    }
    EasyLoading.dismiss();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: ClientColors.ff0a0f12,
      appBar: AppBar(
        backgroundColor: ClientColors.ff0a0f12,
        title: Text(widget.title, style: TextStyle(color: Colors.white, fontSize: 18)),
        iconTheme: IconThemeData(color: Colors.white),
        leading: IconButton(
          onPressed: () => {Get.back()},
          icon: Icon(Icons.arrow_back_ios),
        ),
        elevation: 0,
      ),
      body: Container(
        height: double.infinity,
        margin: EdgeInsets.fromLTRB(16, 20, 16, 20),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(10),
          color: Colors.white,
        ),
        child: Html(data: info),
      ),
    );
  }
}

